package org.example.controller;

import org.example.model.common.dtos.ResponseResult;
import org.example.model.common.vos.dish.SearchDishVo;
import org.example.model.dish.DishBasic;
import org.example.service.DishBasicService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@CrossOrigin
@RestController
@RequestMapping("/dish-basic")
public class DishBasicController {

    @Autowired
    private DishBasicService dishBasicService;

    /**
     * 添加菜品
     * @param dishBasic
     * @return
     */
    @PostMapping("/dish-basic")
    public ResponseResult AddDishBasic(@RequestBody DishBasic dishBasic) {
        return ResponseResult.okResult(dishBasicService.InsertDishBasic(dishBasic));
    }

    /**
     * 根据id查询菜品详情
     */
    @GetMapping("/dish-basic/{id}")
    public ResponseResult GetDishBasicById(@PathVariable int id) {
        return ResponseResult.okResult(dishBasicService.SelectDishById(id));
    }

    /**
     * 根据条件(菜品名称模糊查询，菜品状态精确查询，菜品分类精确查询)查询菜品列表
     */
    @GetMapping("/dish-list/{pageIndex}/{pageSize}")
    public ResponseResult GetDishList(SearchDishVo searchDishVo,@PathVariable int pageIndex,@PathVariable int pageSize) {
        DishBasic dishBasic = new DishBasic();
        BeanUtils.copyProperties(searchDishVo,dishBasic);
        return ResponseResult.okResult(dishBasicService.SelectPageByConditions(dishBasic,pageIndex,pageSize));
    }

    /**
     * 根据id修改对应菜品信息
     */
    @PutMapping("/dish-basic")
    public ResponseResult UpdateDishBasicById(@RequestBody DishBasic dishBasic) {
        return ResponseResult.okResult(dishBasicService.UpdateDishBasicById(dishBasic));
    }

    /**
     * 根据id删除对应菜品信息
     */
    @DeleteMapping("/dish-basic/{id}")
    public ResponseResult DeleteDishBasicById(@PathVariable int id) {
        return ResponseResult.okResult(dishBasicService.DeleteDishBasicById(id));
    }

    /**
     * 根据id修改对应菜品信息
     */
    @PutMapping("/status/{id}")
    public ResponseResult UpdateStatus(@PathVariable int id) {
        return ResponseResult.okResult(dishBasicService.UpdateStatus(id));
    }

    /**
     * 批量修改菜品状态
     */
    @PutMapping("/status-list/{type}")
    public ResponseResult UpdateStatusByIds(@RequestBody int[] ids,@PathVariable int type) {
        return ResponseResult.okResult(dishBasicService.UpdateStatusByIds(ids,type));
    }

    /**
     * 批量删除菜品
     */
    @DeleteMapping("/dish-list")
    public ResponseResult DeleteDishListByIds(@RequestBody int[] ids) {
        return ResponseResult.okResult(dishBasicService.DeleteDishBasicByIds(ids));
    }

    /**
     * 获取不同分类下菜品数据
     */
    @GetMapping("/category-dish-list")
    public ResponseResult GetCategoryDishList() {
        return ResponseResult.okResult(dishBasicService.SelectDishListByCategory());
    }
}
